package com.liudehua.boot.filter;

import com.google.gson.JsonObject;
import com.liudehua.boot.context.Context;
import org.apache.dubbo.common.json.JSON;
import org.apache.dubbo.common.json.ParseException;
import org.apache.dubbo.rpc.*;

public class ExtensionFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        Result result =null;
        String type = invoker.getUrl().getParameter("side");
        if("consumer".equals(type)){
           String param =(String) Context.getInstance().get("contryCode");
            try {
                RpcContext.getContext().setAttachment("_reuse", param);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }else if("provider".equals(type)){
           String contryCode = RpcContext.getContext().getAttachment("_reuse");
            Context.getInstance().put("contryCode",contryCode+"_ES");

        }else {
            throw new RpcException();
        }

        result = invoker.invoke(invocation);
        return result;
    }
}
